1646E - Power Board - CodeForces Solution


brute force dp math number theory *2200

Please click on ads to support us..

C++ Code:

               //  ॐ
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
typedef pair<int,int>       pii;
typedef vector<ll> vll;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
#define pb              push_back 
#define Sort(a)         sort(a.begin(),a.end())
#define ff                  first
#define ss                  second 
const int N = 2e3 +10;
const ll f = 2e18 + 7;

void solve(){
    ll n,m;
    cin>>n>>m;
    vi vis(n+1,0);
    ll ans=1,ct=0;
    vll dp(21,0);
    vll used(3e7,0);
    set<ll> st;

    for (ll i = 1; i < 21; ++i)
    {
        for (ll j = 1; j <= m; ++j)
            if(!used[i*j]) used[i*j]=1,ct++;
        dp[i]=ct;
    }

    for (ll i = 2; i <= n; ++i)
    {
        if(vis[i]) continue;
        vis[i]=1;
        ll ct=1,t=i;
        while(1){
            t*=i;
            if(t>n) break;
            ct++,vis[t]=1;
        }
        ans+=dp[ct];
    }
    cout<<ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t=1;
    // cin>>t;
    while(t--)
        solve();

    return 0;
}


Comments

Submit
0 Comments
More Questions

988B - Substrings Sort
312A - Whose sentence is it
513A - Game
1711E - XOR Triangle
688A - Opponents
20C - Dijkstra
1627D - Not Adding
893B - Beautiful Divisors
864B - Polycarp and Letters
1088A - Ehab and another construction problem
1177B - Digits Sequence (Hard Edition)
1155B - Game with Telephone Numbers
1284A - New Year and Naming
863B - Kayaking
1395B - Boboniu Plays Chess
1475D - Cleaning the Phone
617B - Chocolate
1051B - Relatively Prime Pairs
95B - Lucky Numbers
1692D - The Clock
1553D - Backspace
1670D - Very Suspicious
1141B - Maximal Continuous Rest
1341A - Nastya and Rice
1133A - Middle of the Contest
385A - Bear and Raspberry
1311B - WeirdSort
1713F - Lost Array
236B - Easy Number Challenge
275A - Lights Out